package com.ebb;

import android.app.Activity;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.view.Gravity;
import android.widget.Toast;

public class EBBAlert extends Activity {
	private static Context context;
	private static String title;
	private static String text;
	private static int duration = 0;

	public static Context getContext() {
		return context;
	}

	public static int getDuration() {
		return duration;
	}

	public static void setContext(Context context) {
		EBBAlert.context = context;
	}

	public static void setDuration(int duration) {
		EBBAlert.duration = duration;
	}

	public static void message(int type, String title, String text) {
		EBBAlert.title = title;
		EBBAlert.text = text;
		switch (type) {
		case 0:
			showAlert();
			break;
		case 1:
			threadAgnosticToast();
			break;
		}
	}

	/**
	 * Display a simple alert dialog with the given text and title.
	 * 
	 * @param context
	 *            Android context in which the dialog should be displayed
	 * @param title
	 *            Alert dialog title
	 * @param text
	 *            Alert dialog message
	 */
	public static void showAlert() {
		Builder alertBuilder = new Builder(context);
		alertBuilder.setTitle(title);
		alertBuilder.setMessage(text);
		alertBuilder.create().show();
	}

	public static void threadAgnosticToast() {
		Toast toast = Toast.makeText(context, text, duration);
		toast.setGravity(Gravity.BOTTOM | Gravity.CENTER, 0, 150);
		toast.show();
	}
}